var ns;
var app = new Vue({
    el: '#app',
    data: {
        form: {
            
        },
        Type:1,
        HouseKeeperID:0,
        TagList:[],//标签id
        dzTagList:[],//点赞标签
        tcTagList:[],//吐槽标签
        UseContent:''
    },
    methods: {
        //获取tag标签
        get_TagType:function(){
            var that = this;
            var options = {};
            options.action = 'gethousekeepertaglist';
            ns.post(options, function(succeed, data, err) {
                // console.log(JSON.stringify(data));
                if (succeed) {
                    var taglist=[];
                    taglist=data.data;
                    for (var i = 0; i < taglist.length; i++){
                        if(taglist[i].TagType==8){
                            that.dzTagList.push(taglist[i]);
                        }else{
                            that.tcTagList.push(taglist[i]);
                        }
                    }
                } else if (err) {
                    api.toast({
                        msg: err,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });
        },
        do_tag_select:function(item){
            var that = this;
            item.IsSelect = !item.IsSelect;
        },
        do_save:function(){
            var that=this;
            if(that.Type==1){
                for (var i = 0; i < that.dzTagList.length; i++){
                    if(that.dzTagList[i].IsSelect==true){
                        that.TagList.push(that.dzTagList[i].ID);
                    }
                }
            }
            if(that.Type==2){
                for (var i = 0; i < that.tcTagList.length; i++){
                    if(that.tcTagList[i].IsSelect==true){
                        that.TagList.push(that.tcTagList[i].ID);
                    }
                }
            }
            var options = {};
            options.action = 'savehousekeepercomment';
            options.Type = that.Type;
            options.HouseKeeperID = that.HouseKeeperID;
            options.TagList = that.TagList;
            options.UseContent = that.UseContent;
            ns.post(options, function(succeed, data, err) {
                if (succeed) {
                    // that.do_reset();
                    api.sendEvent({
                        name: 'updatabutler',
                    });
                    api.toast({
                        msg: '提交成功',
                        duration: 2000,
                        location: 'bottom'
                    });
                    api.closeFrame();
                } else{
                    api.toast({
                        msg: data.Msg,
                        duration: 2000,
                        location: 'bottom'
                    });
                }
            }, {
                toast: true
            });

        },

        
        closeframe:function(){
            api.closeFrame();
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.Type = api.pageParam.Type;
    app.HouseKeeperID = api.pageParam.HouseKeeperID;
    app.get_TagType();

};